<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>

</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
        <div id="toolbar" style="float: right"></div>
    </div>
    <div class="page-title-border"></div>
</div>

<div class="search-field">
    <span class="field-cont">
        <span class="field-cont-title">开店人名称</span>
        <input type="text" class="summer-input" id="nickName"/>      
    </span>
    <span class="field-cont">
        <span class="field-cont-title">用户ID</span>
        <input type="text" class="summer-input" id="userId"/>       
    </span><br/>
    
    <span class="field-cont">
     	<span class="field-cont-title">店铺名称</span>
        <input type="text" class="summer-input" id="storeName" />
    </span>
    
    <span class="field-cont">
     	<span class="field-cont-title">手机号</span>
        <input type="text" class="summer-input" id="phone" />
    </span>
    <span class="field-btn-wrapper">
        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
    </span>
</div>

<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <thead>
		    <tr>
		        <th>开店人名称</th>
		        <th>用户ID</th>
		        <th>店铺名称</th>
		        <th>开店时间</th>
		        <th>店主邀请码</th>
		        <th>操作</th>		        
		    </tr>
	    </thead>
    </table>
</div>

<script>
	//请求url
	var CONST_URL = {
		OWNER_LIST: basePath + '${common_url}ownerList',
	   	INIT_ADD: basePath + "${common_url}initAdd",
	   	INIT_EDIT: basePath + "${common_url}ownerMain",
	   	INIT_GOODS: basePath + "${common_url}initGoods"
	};
	
    var  permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
    	
    	
        // 新建toobar
		$.funcbar({
			id: 'toolbar',
			type: 'toolbar',
			data: permission,
			permit: ['${name_english}:initAdd']
		});
        // 查询按钮
        $('#search').on('click', reloadTable);
        
        //重置按钮
        $('#reset').on('click', function () {
        	//重置文本框的值
        	$('#nickName').val('');
        	$('#userId').val(''); 
        	$('#storeName').val(''); 
        	$('#phone').val('');
        	reloadTable();
        });
        
        //新建
        $('#toolbar').on('click', 'a[data-permit="${name_english}:initAdd"]', function() {
        	window.location.href = CONST_URL.INIT_ADD; 	  	
		});
        
        
       createTable();
        
        //查看
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initView"]', function() {
        	var $this = $(this),
        	    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
        	window.location.href = CONST_URL.INIT_VIEW +"?id=" + id;
        });
       
        //店主主页面
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:ownerMain"]', function() {
            var $this = $(this),
                id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_EDIT + '?id=' + id;
        });	
        
        //店铺商品
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initGoods"]', function() {
            var $this = $(this),
                id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_GOODS + '?storeId=' + id;
        });	
        
        //查看用户体系结构
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:viewLevel"]', function() {
            var $this = $(this),
                id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.VIEW_LEVEL + '?id=' + id;
        });
        
        //删除
		$('#t-wrap').on('click', 'a[data-permit="${name_english}:del"]', function() {
			var $this = $(this),
			    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
			$.sdialog({
				type: 'confirm',
				msg: '您确定要删除选中的记录吗?',
				onConfirm: function(result) {
				    if (result) {
				    	$.sajax({
			                url : CONST_URL.DEL + "?id=" + id,
			                onLoadSuccess : function() {
			                	 $.stip({
                	                type:'ok',//显示类型 有info、 ok、 danger
                	                text: '删除成功！'    
			                	});
			                	reloadTable();  
			                }
			            });
				    		
				    }	
				}
			});
		});
        
		//设置黑名单
		$('#t-wrap').on('click', 'a[data-permit="${name_english}:setblack"]', function() {
			var $this = $(this),
			    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
			$.sdialog({
				type: 'confirm',
				msg: '您确定要将此用户设置为黑名单用户吗?',
				onConfirm: function(result) {
				    if (result) {
				    	$.sajax({
			                url : CONST_URL.SETBLACK + "?id=" + id,
			                onLoadSuccess : function() {
			                	 $.stip({
                	                type:'ok',//显示类型 有info、 ok、 danger
                	                text: '设置成功！'    
			                	});
			                	reloadTable();  
			                }
			            });
				    		
				    }	
				}
			});
		});
        
    });
    
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload',{
            ajax: {
            	param: {
            		"nickName": trimSpace($('#nickName').val()),
            		"userId": trimSpace($('#userId').val()),
            		"storeName": trimSpace($('#storeName').val()),
            		"phone": trimSpace($('#phone').val())
            	}
            }
        });
	}
    
    //创建表格
    function createTable() {
    	$('#dataList').datagrid({
    		ajax: {
    			url: CONST_URL.OWNER_LIST,
    			param: {
    				"nickName": trimSpace($('#nickName').val()),
            		"userId": trimSpace($('#userId').val()),
            		"storeName": trimSpace($('#storeName').val()),
            		"phone": trimSpace($('#phone').val())
            	}
    		},
    		columns: [
    		     {
    		    	 field: 'id',
    		    	 hidden: true
    		     },
    		     {
    		    	 field: 'nickName'
    		     },
    		     {
    		    	 field:'userId'
    		     },
    		     {
    		    	 render: function (rowData) {
    		    		 var html = null;
    		    		 html = '<p>'+rowData.storeName+'</p>';
    		    		 return html;
    		    	 }
    		     },
    		     {
    		    	 field: 'createTime'
    		     },
    		     {
    		    	 field: 'inviteCode'
    		     },
    		    {
    		    	 render: function (rowData) {
    		    		 return $.funcbar({
    		    			 data: permission,    //请求的数据
    		    			 type: 'text',     //类型
    		    			 display: 2,    //显示数量
    		    			 permit: ['${name_english}:ownerMain', '${name_english}:initGoods'] //需要的权限按钮
    		    		 });
    		    	 }
    		    }
    		          
    	    ]
    	});
    }

   
   
</script>
</body>
</html>